﻿using System.Text;
using UnityEngine;

public static partial class Utility
{
    
    /// <summary>
    /// 路径工具库
    /// </summary>
    public static class Path
    {

        /// <summary>
        /// 格式化标准路径
        /// </summary>
        /// <param name="path"></param>
        /// <returns>标准路径</returns>
        public static string FormatStandardPath(string path)
        {
            if (path.IsNullOrEmpty())
            {
                return string.Empty;
            }

            return path.Trim().Replace("\\", "/");
        }

        /// <summary>
        /// 获取连接后的路径
        /// </summary>
        /// <param name="path">路径片段</param>
        /// <returns>连接后的路径</returns>
        public static string GetCombinePath(params string[] path)
        {
            if (path == null || path.Length < 1)
            {
                return null;
            }

            string combinePath = string.Empty;
            for (int i = 0; i < path.Length; i++)
            {
                combinePath = System.IO.Path.Combine(combinePath, path[i]);
            }

            return FormatStandardPath(combinePath);
        }


        public static string GetFullPath(string path)
        {
            path = path.Replace("\\", "/");
            string assetPath = path;
            int index = path.IndexOf("Assets/");
            if (index != -1)
            {
                assetPath = path.Substring(index + "Assets/".Length);
            }
            return System.IO.Path.GetFullPath(Application.dataPath.Combine(assetPath)).Replace("\\", "/");
        }
    }
}
